Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Pull request stats
Reviewable churn: 254 lines (net +244), version bumps and generated files excluded. New files: 1
Package source changed without an update to |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #488 +/- ##
==========================================
+ Coverage 89.25% 89.28% +0.02%
==========================================
Files 61 62 +1
Lines 5082 5096 +14
Branches 950 952 +2
==========================================
+ Hits 4536 4550 +14
Misses 421 421
Partials 125 125 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
libauth's BCH 2026 VM does not add the function body length to the operation cost on OP_DEFINE, while BCHN does (bitauth/libauth#166). The SDK now wraps OP_DEFINE when it creates the BCH_2026_05 and BCH_SPEC VMs, so getVmResourceUsage(), debug() and the MockNetworkProvider charge the body too. Only the part libauth did not charge itself is added, so a fixed libauth is not counted twice. Part of #481 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mr-zwets
force-pushed
the
fix/libauth-op-define-cost
branch
from
December 2, 2026 12:11
c401c16 to
674b838
Compare
virtual-machine.ts exports drop-in replacements for libauth's createVirtualMachineBch2026 and createVirtualMachineBchSpec that charge the function body on OP_DEFINE, so createVirtualMachine in utils.ts only changes where it imports them from.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
libauth's BCH 2026 VM does not add the length of the function body to the operation cost when
OP_DEFINEruns, while BCHN does (bitauth/libauth#166). cashc emitsOP_DEFINEfor every function or global constant that is not inlined, and the SDK evaluates everything through libauth, so for those contracts:getVmResourceUsage()under-reportsoperationCostby the total length of the defined bodies.debug()and theMockNetworkProvideraccept transactions that the network rejects for exceeding the op-cost budget.The latest libauth prerelease (
3.1.0-next.8) is from September 2025 and the upstream issue has no maintainer response, so this fixes it in the SDK. See #481 for the full analysis.Change
createVirtualMachineinlibauth-template/utils.tsis the single place where the SDK creates a VM. ForBCH_2026_05andBCH_SPECit now builds the VM from libauth's instruction set withOP_DEFINEwrapped: when a function is defined, the wrapper adds the body length tometrics.stackPushedBytes, which libauth turns into operation cost and checks against the budget after each instruction. Only public libauth API is used.BCH_2023_05andBCH_2025_05are untouched, because they have noOP_DEFINE.All three packages depend on
^3.1.0-next.8, so a user can get a fixed libauth without a new CashScript release. To keep the cost from being counted twice in that case, the wrapper only adds the part of the body that the wrappedOP_DEFINEdid not already add tostackPushedBytes.Known limit: this recognises an upstream fix that charges through
stackPushedBytesinsideOP_DEFINE, which is what the CHIP describes and what bitauth/libauth#166 suggests. A fix that charges through another metric, or outside the operation, would be counted twice. The "is still needed" test below fails on any upstream fix, so a libauth bump in this repo cannot pass unnoticed.Behaviour change
Reported op-cost goes up for contracts with non-inlined functions or constants. A transaction close to its budget that passed
debug()or theMockNetworkProviderbefore can now fail, as it would on a node. Compiled bytecode is unchanged.Tests
Direct VM tests in the new
test/libauth-template/virtual-machine.test.ts, forBCH_2026_05andBCH_SPEC:<body> <0> OP_DEFINE <1>costs401 + 2 × body length.OP_DEFINEin a branch that is not executed is not charged, with a body and identifier on the stack.OP_DEFINEalready charges the body, the wrapper adds nothing.SDK tests in
test/debugging.test.ts(VM Resources):debug()trace of a compiled contract, theOP_DEFINEstep costs100 + body length.debug()rejects the transaction and so doesMockNetworkProvider.sendRawTransaction(), and the measured usage shows it would have fit without the body charge.Each part of the wrapper was checked by breaking it: with no charge 4 tests fail, with the charge applied to skipped branches 2 fail, with the already-charged bytes ignored 1 fails, and with the
MockNetworkProvideron a stock VM 1 fails. The full test suite, lint and spellcheck pass.Release notes
Not changed in this PR, because the docs deploy from
master. Proposed entries for the next release (v0.14.1), including the other SDK fix merged sincev0.14.0:Not included
OP_INVOKEand the last code separator) and the DER signature length bounds (fix(vm): accept DER signature length boundaries bitauth/libauth#165). cashc never emitsOP_CODESEPARATOR, and fixing only fetch utxos when necessary #167 means replacing libauth'scontinueloop instead of wrapping one operation. Both stay tracked in Tracking: libauth VM differences from BCHN, and working around them in the SDK #481.Part of #481.
🤖 Generated with Claude Code